#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[]){
    if(argc != 3){
        printf("Usage:%s <device(/dev/led_drv)>  <on/off>\n", argv[0]);
        return -1;
    }

    if(strcmp(argv[2],"0") != 0 && strcmp(argv[2], "1") != 0)
    {
        printf("argv[1] should be on or off\n");
        return -1;
    }

    int fd = open(argv[1], O_RDWR);
    if(fd == -1)
    {
        perror("open");
        return -1;
    }
    
    int len = write(fd, argv[2], sizeof(argv[2]));
    if(len < 0 ){
        perror("write");
        close(fd);
        return -1;
    } 

    close(fd);  // Clean up file descriptor
    return 0;
}